package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.UserInsertRequestDTO;
import com.example.child_protection.dto.request.find.CkeckUserNameRequestDTO;
import com.example.child_protection.dto.request.find.UserPageQueryRequestDTO;
import com.example.child_protection.dto.request.find.UserQueryRequestDTO;
import com.example.child_protection.dto.request.update.UserUpdatePwdRequestDTO;
import com.example.child_protection.dto.request.update.UserUpdateRequestDTO;
import com.example.child_protection.dto.response.CheckUserResponseDTO;
import com.example.child_protection.dto.response.UserPageResponseDTO;
import com.example.child_protection.dto.response.UserResponseDTO;
import com.example.child_protection.service.UserManageService;
import com.example.child_protection.service.UserQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户信息管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("user")
@Api(value = "/api-user", description = "用户信息管理")
public class UserController extends BaseController {

    @Autowired
    public UserManageService userManageService;

    @Autowired
    public UserQueryService userQueryService;

    @ApiOperation(value ="查询用户信息（分页）", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findPage", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO findPage(UserPageQueryRequestDTO requestDTO)throws Exception{
        UserPageResponseDTO responseDTO = userQueryService.findPage(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询单个用户信息（id）", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO findId(SimpleIdRequestDTO requestDTO)throws Exception{
        UserResponseDTO responseDTO = userQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="检测用户名是否可用", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/checkUserName", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CheckUserResponseDTO checkUserName(CkeckUserNameRequestDTO requestDTO)throws Exception{
        CheckUserResponseDTO responseDTO = userQueryService.checkUserName(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改密码", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/updatePwd", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO updatePwd(UserUpdatePwdRequestDTO requestDTO)throws Exception{
        BaseResponseDTO responseDTO = userManageService.updatePwd(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加用户信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(UserInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(1L);
        requestDTO.setLastUpdatePersonId(1L);
        BaseResponseDTO responseDTO = userManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改用户信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(UserUpdateRequestDTO requestDTO)throws Exception{
        BaseResponseDTO responseDTO = userManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除用户信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = userManageService.delete(requestDTO);
        return responseDTO;
    }

}
